package com.longxiao.manager.web;

import com.longxiao.entity.Classroom;
import com.longxiao.service.ClassroomService;
import com.longxiao.vo.PageVo;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

/**
 * 预约情况查看
 * Created by houhongwei on 2017/5/22.
 */
@Controller
public class AppointmentController extends BaseController {

    @Autowired
    ClassroomService classroomService;

    /**
     * 预约情况查看
     * @return
     */
    @RequestMapping(value = "/appointment/show", method = {RequestMethod.GET,RequestMethod.POST})
    public ModelAndView viewAppiontment(@RequestParam(value = "startTime", required = false) String startTime,
                                  @RequestParam(value = "endTime", required = false) String endTime,
                                  @RequestParam(value = "stuId", required = false) String stuId,
                                  @RequestParam(value = "tchId", required = false) String tchId,
                                  @RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
                                  HttpServletRequest request) {
    	if(StringUtils.isNotEmpty(startTime)) {
    		startTime = startTime + " 00:00:00";
    	}
    	if(StringUtils.isNotEmpty(endTime)) {
    		endTime = endTime + " 23:59:59";
    	}
    	ModelAndView mav = new ModelAndView("appointment/list");
        int count = classroomService.selectAllClassroomCount(startTime, endTime,tchId,stuId);
        PageVo<Classroom> pageObj = new PageVo<Classroom>(pageNum, count);
        List<Classroom> list = classroomService.selectAllClassroom(startTime, endTime,tchId,stuId, pageObj.getOffset(), pageObj.getRows());
        pageObj.setData(list);
        mav.addObject("page", pageObj);
        mav.addObject("currPage", pageNum);
        this.initParam(request, mav);
        
        return mav;
    }

}
